package offersimple

import "container/list"

type CQueue struct {
	s1, s2 *list.List
}

func ConstructorCQueue() CQueue {
	return CQueue{
		s1: list.New(),
		s2: list.New(),
	}
}

func (q *CQueue) AppendTail(value int) {
	q.s2.PushBack(value)
}

func (q *CQueue) DeleteHead() int {
	if q.s1.Len() == 0 {
		for q.s2.Len() > 0 {
			q.s1.PushBack(q.s2.Remove(q.s2.Back()))
		}
	}
	if q.s1.Len() != 0 {
		result := q.s1.Back()
		q.s1.Remove(result)
		return result.Value.(int)
	}
	return -1
}

type CQueueSlice struct {
	s1, s2 []*int
}

func ConstructorSlice() CQueueSlice {
	return CQueueSlice{}
}
func (q *CQueueSlice) AppendTail(value int) {
	q.s2 = append(q.s2, &value)
}

func (q *CQueueSlice) DeleteHead() int {
	if len(q.s1) == 0 {
		q.s1 = append(q.s1, q.s2...)
		q.s2 = []*int{}
	}
	if len(q.s1) != 0 {
		result := q.s1[0]
		q.s1 = q.s1[1:]
		return *result
	}
	return -1
}
